package com.livestocksolutions.ui;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.livestocksolutions.R;
import com.livestocksolutions.intent.BaseActivity;

/* -- Version History --
 *  1.0 : 17 September 2012 - Initial version.
 */

/**
 * A base class to create the layout for the list of Used Items used on an Object
 * @author Adam Parr
 * @version 1.0
 * 
 * @.modified 19 October 2012
 */
public class ListMedicalHistoryArrayAdapter extends BaseArrayAdapter {
	/**
	 * Size of the allowable array passed
	 */
	public static final int SIZE = 4;
	/**
	 * ID of the Vet Business position within the String[position][{@value #VET}] array passed in the Constructor.
	 */
	public static final int VET = 0;
	/**
	 * The Date this was Used position within the String[position][{@value #DATE}] array passed in the Constructor.
	 */
	public static final int DATE = 1;
	/**
	 * The cost of the visit position within the String[position][{@value #COST}] array passed in the Constructor.
	 */
	public static final int COST = 2;
	/**
	 * Comments regarding visit position within the String[position][{@value #COMMENT}] array passed in the Constructor.
	 */
	public static final int COMMENT = 3;
 
	public static final int ID = 0;
	public static final int NAME = 1;
	/**
	 * The list of owner that will be selectable.
	 */
	protected String[][] owner = new String[][]{};
	
	
	/**
	 * Constructor
	 * @param context The current context.
	 * @param values The Medical History to represent in the ListView.
	 */
	public ListMedicalHistoryArrayAdapter(BaseActivity context, String[][] values) {
		super(context, values);
	}
	
	/**
	 * Set the TextView id to inflate when creating this list
	 * @param textViewResourceId the TextView id to inflate when {@link #getView(int, View, ViewGroup)} is called.
	 */
	@Override
	public void setView(int textViewResourceId){
		this.textViewResourceId=textViewResourceId;
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		setView(R.layout.item_medicalhistory_view);
		View rowView = super.setView(position, convertView, parent);
		
		TextView medicalDate = (TextView) rowView.findViewById(R.id.medicalDate);
		TextView medicalVet = (TextView) rowView.findViewById(R.id.medicalVet);
		TextView medicalComment = (TextView) rowView.findViewById(R.id.medicalComment);
		TextView medicalCost = (TextView) rowView.findViewById(R.id.medicalVisitCost);
		
		values[position][DATE]=values[position][DATE]!=null?values[position][DATE]:"";
		
		for(int x=0; x < owner.length; x++){
			if(values[position][VET]==null || owner[x][ID].equals(values[position][VET])){
				medicalVet.setText(owner[x][NAME]);
				break;
			}
		}
		
		String s = context.format(context.parse(values[position][DATE]));
		medicalDate.setText(!s.equals("")?s:context.getResources().getString(R.string.message_noText,context.getResources().getString(R.string.message_notSet)));
		medicalCost.setText(values[position][COST]);
		medicalComment.setText(values[position][COMMENT]);
		
		return rowView;
	}
	
	/**
	 * Set the list of Businesses that this visit could have occurred by.<br>
	 * The structure of this list is expected to be the First Dimension containing each Business,
	 * the Second Dimension is structured with {@link #ID} and {@link #NAME}, with ID containing
	 * a String representation of the long id of that business, and NAME containing the name of the
	 * business.
	 * @param ownerList The String Array to use as the list of businesses.
	 */
	public void setOwnerList(String[][] ownerList){
		owner = ownerList;
	}
}
